package com.netintech.intelligenceInterface.test;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.Semaphore;

/**
 * @author lining
 * @date 2021/4/28 13:52
 * 接口压力测试
 */
@RestController
@RequestMapping("/test")
public class ApiPressureTestController {

    private final Semaphore permit = new Semaphore(10, true);

    @PostMapping("/pressure")
    public String test() {
        try {
            permit.acquire();
            System.out.println("处理请求===============>");
            Thread.sleep(2000);
        } catch (Exception e) {
            System.out.println("error");
        } finally {
            permit.release();
        }
        return "success";
    }
}
